package com.cn.kehong.controller;


import com.cn.kehong.api.IProductDianciRecordService;
import com.cn.kehong.domain.ProductDianciRecord;
import com.cn.kehong.domain.ProductGzPeriod;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/dianrecord")
public class ProductDianciRecordController {

    @Autowired
    private IProductDianciRecordService productDianciRecordService;

    @RequestMapping("/getProductDianciRecordList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProductDianciRecord>> getProductDianciRecordList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<ProductDianciRecord> > response = new JsonResponse<List<ProductDianciRecord> >();
        List<ProductDianciRecord> lists = productDianciRecordService.getProductDianciRecordList(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/updateProductDianciRecord/{frontToken}")
    @ResponseBody
    public JsonResponse<String> updateProductDianciRecord(ProductDianciRecord productDianciRecord, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productDianciRecordService.updateProductDianciRecord(productDianciRecord);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/addProductDianciRecord/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addProductDianciRecord(ProductDianciRecord productDianciRecord, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productDianciRecordService.addProductDianciRecord(productDianciRecord);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/deleteProductDianciRecord/{frontToken}")
    @ResponseBody
    public JsonResponse<String> deleteProductDianciRecord(String id, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = productDianciRecordService.deleteProductDianciRecord(id);
        return CommonUtil.getResponseData(response,result);
    }
}
